From: Brion Vibber Date: Sat, 12 Jul 2008 14:05:04 +0000 (+0000) Subject: Revert r37567 for nwo ("(bug 8604) padright: and similar functions fail with non... X-Git-Tag: 1.31.0-rc.0~46536 X-Git-Url: http://git.cyclocoop.org/%22.%24info%5B?a=commitdiff_plain;h=4aedae21267370c25f8ffeed6409b02501844881;p=lhc%2Fweb%2Fwiklou.git Revert r37567 for nwo ("(bug 8604) padright: and similar functions fail with non-ASCII arguments") This implements an mb_str_pad fallback function, but there is no mb_str_pad in PHP documentation, and the doc comments are really weird -- it says it returns an integer! If this function is created from whole cloth and doesn't exist in PHP, it should be given a MediaWiki style name and not be done with a function_exists check as though it were a compat function. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index be5952ea59..8ad7e7083e 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -431,7 +431,6 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN had stict standards issues with setFakeSlaveLag() and setFakeMaster(). * (bug 451) Improve the phrase mappings of the Chinese converter arrays. * (bug 12487) Rights log is not fully internationalized -* (bug 8604) padright: and similar functions fail with non-ASCII arguments === API changes in 1.13 === diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index b4e018533c..56a313fa0f 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -70,29 +70,6 @@ if ( !function_exists( 'mb_strlen' ) ) { } } -if ( !function_exists( 'mb_str_pad' ) ) { - /** - * Fallback implementation of mb_str_pad, hardcoded to UTF-8. - * @param $input String: input string - * @param $pad_length Integer: how much to pad - * @param $pad_string Character used for padding, only one! - * @param $pad_type Only STR_PAD_LEFT and STR_PAD_RIGHT supported. - * @return int - */ - function mb_str_pad( $input, $pad_length, $pad_string, $pad_type ) { - $toPad = $pad_length - mb_strlen( $input ); - if ( $toPad <= 0 ) return $input; - for ( $i = 0; $i < $toPad; $i++ ) { - if ( $pad_type === STR_PAD_LEFT ) { - $input = $pad_string . $input; - } elseif( $pad_type === STR_PAD_RIGHT ) { - $input .= $pad_string; - } - } - return $input; - } -} - if ( !function_exists( 'array_diff_key' ) ) { /** * Exists in PHP 5.1.0+ diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index 58f5eb652c..d9072e9310 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -287,9 +287,9 @@ class CoreParserFunctions { static function pad( $string = '', $length = 0, $char = 0, $direction = STR_PAD_RIGHT ) { $length = min( max( $length, 0 ), 500 ); - $char = mb_substr( $char, 0, 1 ); - return ( $string !== '' && (int)$length > 0 && mb_strlen( trim($char) ) > 0 ) - ? mb_str_pad( $string, $length, $char, $direction ) + $char = substr( $char, 0, 1 ); + return ( $string !== '' && (int)$length > 0 && strlen( trim( (string)$char ) ) > 0 ) + ? str_pad( $string, $length, (string)$char, $direction ) : $string; }